package cn.alm.springaihello.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("client")
public class ClientController {

    @Resource
    private ChatClient chatClient;

    @GetMapping("chat")
    public String chat(@RequestParam String prompt) {
        String content = chatClient.prompt().user(prompt).call().content();
        return content;
    }

    @GetMapping(value = "stream", produces = "text/html;charset=UTF-8")
    public Flux<String> stream(@RequestParam String question) {
        Flux<String> content = chatClient.prompt(question).stream().content();
        return content;
    }

}
